package javaTec.ThreadPrograming;

import java.io.InterruptedIOException;

/**
 * Created by yangshunxing on 2017/10/10.
 */
public class CompareSerialConcurrency {

    private static final long count = 10000l;

    public static void main(String[] args) throws InterruptedException {
       concurrency();
       serial();
    }

    public static void concurrency() throws InterruptedException {
        long startTime = System.currentTimeMillis();
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                int a = 0;
                for (int i=0; i<count; i++){
                    a += 5;
                }
            }
        });
        thread.start();
        int b = 0;
        for (int i = 0; i < count; i++){
            b -=5;
        }
        thread.join();
        System.out.println("多线程处理时间："+(System.currentTimeMillis() - startTime) + "---b:"+b);
    }

    public static void serial(){
        long startTime = System.currentTimeMillis();
        int a = 0;
        for (int i = 0; i < count; i++){
            a +=5;
        }
        int b = 0;
        for (int i = 0; i < count; i++){
            b -=5;
        }
        System.out.println("单线程处理时间:"+(System.currentTimeMillis()-startTime)+"---a:"+ a + "---b:"+b);
    }
}

